# Maintainer: christian rebischke <chris.rebischke@archlinux.org>
# Contributor: ml <ml@visu.li>
pkgname=kubectl-ingress-nginx
_pkgname=${pkgname#kubectl-}-controller
_bin=kubectl-ingress_nginx
pkgver=1.0.4
pkgrel=2
pkgdesc='kubectl plugin for managing NGINX Ingress Controller for Kubernetes'
arch=('loong64' 'x86_64')
url='https://github.com/kubernetes/ingress-nginx'
license=('Apache')
depends=('glibc')
makedepends=('go' 'git')
groups=('kubectl-plugins')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/kubernetes/ingress-nginx/archive/refs/tags/controller-v${pkgver}.tar.gz")
sha512sums=('65017d83df1640c5f97cbe7bc121a3581f98b60fb6f51415cc17bc8513df9d597057f7a3ed37c0623a3cb38536e55607fe75645d8a561583cfcbd2e7c06b1961')
b2sums=('97f25eca3366bf3ea59957083a6538417fef5908c9f7a6b4f4c7d3161a304591f09970509f2bf49023c87ff225a2c7aa4f5d4930641ec78b954d5914616e250e')

build() {
  cd "${_pkgname}-v${pkgver}"

  export CGO_LDFLAGS="$LDFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export GOFLAGS='-buildmode=pie -trimpath -modcacherw -mod=readonly'
  go build -o "${_bin}" -ldflags "-w -s -linkmode=external" ./cmd/plugin
}

package() {
  cd "${_pkgname}-v${pkgver}"
  install -Dm755 ${_bin} -t "${pkgdir}/usr/bin"
  install -Dm644 docs/kubectl-plugin.md -t "${pkgdir}/usr/share/doc/${pkgname}"
}
